package com.shop.milk_tea_shop.controller;

import com.shop.milk_tea_shop.common.CodeEnum;
import com.shop.milk_tea_shop.common.GlobalInfo;
import com.shop.milk_tea_shop.common.Result;
import com.shop.milk_tea_shop.entity.UserInfo;
import com.shop.milk_tea_shop.request.PagedRequest;
import com.shop.milk_tea_shop.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjw
 * @since 2024-06-16
 */
@RestController
@RequestMapping("/userInfo")
public class UserInfoController {

    @Autowired
    UserInfoService userInfoService;

    @PostMapping("/paged")
    public Result<List<UserInfo>> paged(PagedRequest request){

        return userInfoService.paged(request);
    }

    @GetMapping("/{id}")
    public Result<UserInfo> getByID(@PathVariable long id){
        UserInfo result = userInfoService.getById(id);
        return new Result<>(CodeEnum.SUCCESS.getMsg(), CodeEnum.SUCCESS, result, new GlobalInfo());
    }

    @PostMapping("/add")
    public Result<UserInfo> add(UserInfo userInfo){
        return userInfoService.add(userInfo);
    }

    @PutMapping
    public Result<Boolean> update(UserInfo userInfo){
        boolean res = userInfoService.updateById(userInfo);
        return new Result<>(CodeEnum.SUCCESS.getMsg(), CodeEnum.SUCCESS, res, new GlobalInfo());
    }
}
